package me.helllp.dake.iam.core.rest;

import me.helllp.dake.common.MessageCode;
import me.helllp.dake.common.base.BaseController;
import me.helllp.dake.common.base.BaseResult;
import me.helllp.dake.common.exception.DakeDataExistedException;
import me.helllp.dake.core.bean.DakeAuthAccount;
import me.helllp.dake.core.utils.AccountUtil;
import me.helllp.dake.core.utils.MessageUtils;
import me.helllp.dake.iam.core.dto.TenantDto;
import me.helllp.dake.iam.core.dto.UserDto;
import me.helllp.dake.iam.core.service.ITenantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 租户信息管理
 *
 * @author 林晓明
 */
@RestController
@RequestMapping("/system/tenant")
public class DakeTenantController extends BaseController {
    @Autowired
    private ITenantService service;

    @PostMapping(path = "/add")
    public BaseResult<?> addTenant(@RequestBody TenantDto tenantDto) throws DakeDataExistedException {
        // 登录用户信息
        DakeAuthAccount account = AccountUtil.toAuthAccount();
        Assert.notNull(account, MessageUtils.message(MessageCode.MSG_AUTH_NOT_LOGIN));
        // 入参信息
        Assert.notNull(tenantDto, MessageUtils.message(MessageCode.ERROR_INPUT_PARAMETER));
        Assert.notNull(tenantDto.getTenantCode(), MessageUtils.message(MessageCode.ERROR_INPUT_PARAMETER));
        Assert.notNull(tenantDto.getTenantName(), MessageUtils.message(MessageCode.ERROR_INPUT_PARAMETER));
        Long tenantId = service.createTenant(account, tenantDto);
        return BaseResult.success(tenantId);
    }
}
